package com.线程池;

import java.util.concurrent.*;

public class ThreadPoolDemo {
    public static void main(String[] args) {
        Runnable run = new RunnableDemo();

        //创建线程池
        ExecutorService pool = new ThreadPoolExecutor(
                3,//正事工三个
                5,//员工最多是5个
                6, TimeUnit.SECONDS,//临时员工存活的最大时间 6s
                new ArrayBlockingQueue<>(5),//队列 沙发做着等着线程处理完的任务
                Executors.defaultThreadFactory(),//指定线程工厂创建线程
                new ThreadPoolExecutor.AbortPolicy()//对于处理不了的线程 的处理方式
        );

        //处理线程
        pool.execute(run);
        pool.execute(run);
        pool.execute(run);

        pool.execute(run);
        pool.execute(run);
        pool.execute(run);
        pool.execute(run);
        pool.execute(run);

        //再创建一个线程就要雇佣临时线程了
        pool.execute(run);
        pool.execute(run);

        //在创建就要报错了
        pool.execute(run);
    }
}
